#include "mcu_clib.h"
#include <string.h> 

#ifndef _WIN32

void  memcpy_s(void* dest, DWORD  destSize, const void* src, DWORD srcLen)
{ 
	if ((char*)dest > (char*)src && (char*)dest < (char*)src + destSize) {
		char* tempdest = (char*)dest + destSize - 1;
		const char* tempsrc = (const char*)src + destSize - 1;
		while (destSize--) {
			*tempdest = *tempsrc;
			tempsrc = tempsrc - 1;
			tempdest = tempdest - 1;
		}
	}
	else {  
		char* tempdest = (char*)dest;
		const char* tempsrc = (const char*)src;
		DWORD cpLen=__min(destSize,srcLen);
		while (cpLen--) {
			*tempdest = *tempsrc;
			tempsrc = tempsrc + 1;
			tempdest = tempdest + 1;
		}
	}
	return ;

}

int strcpy_s(char *strDestination , DWORD numberOfElements , const char *strSource){
	while (numberOfElements--) *strDestination++ = *strSource++;
	return 0;
}

void strcat_s(char *strDestination , DWORD numberOfElements , const char *strSource){

	  char* temp = strDestination;
    while (*temp != '\0') temp++;
    while ((*temp++ = *strSource++) != '\0' && numberOfElements>0){
		   numberOfElements--;
		}
    return ;

}

#endif 
